package cn.lb.org.service.impl;

import cn.lb.basic.service.impl.BaseServiceImpl;
import cn.lb.org.domain.Employee;
import cn.lb.org.mapper.EmployeeMapper;
import cn.lb.org.query.EmployeeQuery;
import cn.lb.org.service.IEmployeeService;
import cn.lb.permission.domain.Role;
import cn.lb.permission.dto.EmployeeRoleDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
@Service
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService {
    @Autowired
private EmployeeMapper employeeMapper;

    @Override
    public List<Employee> trees() {
        List<Employee> tree = employeeMapper.tree();
        return tree;
    }

    @Override
    public void setrole(EmployeeRoleDTO dto) {
        List<Long> list=new ArrayList<>();
        employeeMapper.deleterole(dto.getEmployeeId());
        List<Role> roles = dto.getRoles();
        for(Role t:roles){
            String sn = t.getSn();
            Long id = employeeMapper.getRoleIdBySn(sn);
            list.add(id);
        }
        employeeMapper.setroles(dto.getEmployeeId(),list);
    }


}
